<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>权限列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '修改',
	        iconCls: 'icon-edit',
	        handler: function () {
                var row = $('#userlist').datagrid("getSelected");
	            $.ajax({
                    url:"/manager/permission/findById",
                    data: {id: row.id},
                    dataType: 'json',
                    method: 'get',
                    success: function (res) {
                        if (res.code = 200){
                            $("#id").textbox("setValue", res.data.id);
                            $("#name").textbox("setValue", res.data.name);
                            $("#sname").textbox("setValue", res.data.sname);
                            $("#url").textbox("setValue", res.data.url);
                            $('#parents').combobox('reload','/manager/permission/findAllParents');
                            $('#parents').combobox('setValue', res.data.parentid);
                            // $('#parents').combobox('setValues', ['001','002']);
                        }else {
                            alert("查询错误");
                        }
                    }
                })
	            $('#dd').dialog('open');
	        }
	    }];
	   $(function(){
	       $('#userlist').datagrid({  
			title:'权限列表',
               singleSelect:true,
			iconCls:'icon-save',   
			// url:'json/datagrid_data1.json',
               url: "/manager/permission/findAll",
			columns:[
			    [
				{field:'id',title:'权限ID',width:100,align:'center'},
				{field:'name',title:'权限名称',width:100,align:'center'},
				{field:'url',title:'权限URL',width:100,align:'center'},
				{field:'parent',title:'权限所在模块',width:80,align:'center', formatter: function (value) {
				        return value == null ? null: value.name;
				        // console.log(value);
                        // return value.name;
                    }},
				{field:'sname',title:'权限操作名称',width:200,align:'center'}
			]
            ],
			pagination:true,
			toolbar: toolbar  
		});
		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                var permissionName = $("#permissionName").val();
                var parentName = $("#parentName").val();
                console.log(name);
                console.log(parentName);
                $('#userlist').datagrid(
                    { queryParams:{
                            permissionName:permissionName,
                            parentName:parentName
                        }
                    });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        modifyPermission();
                        alert('ok');
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
			});
            
	   });
	   
	   
	   function modifyPermission() {

	       console.log("父亲id", $("#parents").combobox("getValue"));
           $.ajax({
               url:"/manager/permission/modifyPermission",
               data: {
                   id: $("#id").val(),
                   name: $("#name").val(),
                   sname: $("#sname").val(),
                   parentid: $("#parents").combobox("getValue")
               },
               dataType: 'json',
               method: 'get',
               success: function (res) {
                    if(res.code == 200){
                        alert("success");
                        $("#dd").dialog("close");
                        $("#userlist").datagrid("reload");
                    }
               }
           })
       }
	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>权限查询：</strong></td>
    <td height="30">
        <input type="text" id="parentName" name="keyword" size=20 placeholder="模块名称"/>
        <input type="text" id="permissionName" name="keyword" size=20 placeholder="权限名称"/>
        <a id="submit_search">搜索</a>
    </td>
  </form>
  <table id="userlist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input id="id" class="easyui-textbox" name="name" style="width:50%" data-options="label:'权限ID:'" readonly="readonly"/>
            </div>
             <div style="margin-bottom:20px">
                <input id="url" class="easyui-textbox" name="name" style="width:50%" data-options="label:'权限url:'" readonly="readonly"/>
            </div>
            <div style="margin-bottom:20px">
                <input id="name" class="easyui-textbox" name="name" style="width:50%" data-options="label:'权限名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input id="sname" class="easyui-textbox" name="email" style="width:50%" data-options="label:'操作名称:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <select id="parents" class="easyui-combobox" name="language" label="所属模块:" style="width:50%" data-options="valueField:'id',textField:'name',multiple:false" >
		            <!--<option value="-1">请选择模块</option>-->
		            <!--<option value="be_name" >用户管理</option>-->
		            <!--<option value="be_intro">权限管理</option>-->
		            <!--<option value="be_intro">元数据管理</option>-->
		        </select>
            </div>
        </form>
           </div>
    </div>
</body>
</html>